package us.sunrisemorning.mykancolle.battle;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import us.sunrisemorning.mykancolle.config.GameData;
import us.sunrisemorning.mykancolle.model.Ship;

public class BattleShip {
    private int id;
    private int level;
    private int nowhp;
    private int maxhp;
    private int[] param = new int[] { 0, 0, 0, 0 };
    private int[] slot = new int[] { -1, -1, -1, -1, -1 };

    private boolean friend;

    public void loadFShip(Ship ship) {
        id = ship.getId().intValue();
        level = ship.getLv();

        nowhp = ship.getNowhp();
        maxhp = ship.getMaxhp();

        param[0] = ship.getKaryoku1();
        param[1] = ship.getRaisou1();
        param[2] = ship.getTaiku1();
        param[3] = ship.getSoukou1();

        slot[0] = ship.getSlot1();
        slot[1] = ship.getSlot2();
        slot[2] = ship.getSlot3();
        slot[3] = ship.getSlot4();
        slot[4] = ship.getSlot5();

        friend = true;
    }

    public void loadEShip(int shipId) {
        JSONObject shipData = GameData.getEnemyShipData().get(shipId);

        id = shipId;
        level = 1;

        nowhp = shipData.getIntValue("hp");
        maxhp = nowhp;

        JSONArray params = shipData.getJSONArray("param");
        param[0] = params.getIntValue(0);
        param[1] = params.getIntValue(1);
        param[2] = params.getIntValue(2);
        param[3] = params.getIntValue(3);

        JSONArray slots = shipData.getJSONArray("slot");
        slot[0] = slots.getIntValue(0);
        slot[1] = slots.getIntValue(1);
        slot[2] = slots.getIntValue(2);
        slot[3] = slots.getIntValue(3);
        slot[4] = slots.getIntValue(4);

        friend = false;
    }

    public int getId() {
        return id;
    }

    public int getLevel() {
        return level;
    }

    public int getNowhp() {
        return nowhp;
    }

    public void setNowhp(int nowhp) {
        this.nowhp = Math.max(friend ? 1 : 0, nowhp);
    }

    public int getMaxhp() {
        return maxhp;
    }

    public int[] getParam() {
        return param;
    }

    public int[] getSlot() {
        return slot;
    }

    public boolean canRaigeki() {
        return param[1] > 0;
    }

    public boolean isDead() {
        return nowhp == 0;
    }

    public boolean isFriend() {
        return friend;
    }
}
